<?php

class Table_Shop_Module extends Module{

    public function insert(array $post){
        $data = array(
            'city_id'    => array_get_int($post, 'city_id'),
            'type_id'    => array_get_int($post, 'type_id'),
            'zone_id'    => array_get_int($post, 'zone_id'),
            'subzone_id' => array_get_int($post, 'subzone_id'),
            'name'       => array_get_string($post, 'name'),
            'alias_name' => array_get_string($post, 'alias_name'),
            'address'    => array_get_string($post, 'address'),
            'telphone'   => array_get_string($post, 'telphone'),
            'mobile'     => array_get_string($post, 'mobile'),
            'topic'      => array_get_string($post, 'topic'),
            'worktime'   => array_get_string($post, 'worktime'),
            'traffic'    => array_get_string($post, 'traffic'),
            'longitude'  => array_get_double($post, 'longitude'),
            'latitude'   => array_get_double($post, 'latitude'),
            'status'     => array_get_int($post, 'status'),
            'star'       => array_get_int($post, 'star'),
            'views'      => array_get_int($post, 'views'),
            'likes'      => array_get_int($post, 'likes'),
            'create_dt'  => date('Y-m-d H:i:s', TIMESTAMP),
            'create_uid' => App::getUser()->getUid(),
            'update_dt'  => date('Y-m-d H:i:s', TIMESTAMP),
            'updat_uid'  => App::getUser()->getUid(),
        );

        return Db::insert(Db::table('shop'), $data);
    }

    public function update($shop_id, array $post){
        $shop_id = intval($shop_id);
        $data = array(
            'city_id'    => array_get_int($post, 'city_id'),
            'type_id'    => array_get_int($post, 'type_id'),
            'zone_id'    => array_get_int($post, 'zone_id'),
            'subzone_id' => array_get_int($post, 'subzone_id'),
            'name'       => array_get_string($post, 'name'),
            'alias_name' => array_get_string($post, 'alias_name'),
            'address'    => array_get_string($post, 'address'),
            'telphone'   => array_get_string($post, 'telphone'),
            'mobile'     => array_get_string($post, 'mobile'),
            'topic'      => array_get_string($post, 'topic'),
            'worktime'   => array_get_string($post, 'worktime'),
            'traffic'    => array_get_string($post, 'traffic'),
            'longitude'  => array_get_double($post, 'longitude'),
            'latitude'   => array_get_double($post, 'latitude'),
            'status'     => array_get_int($post, 'status'),
            'star'       => array_get_int($post, 'star'),
            'views'      => array_get_int($post, 'views'),
            'likes'      => array_get_int($post, 'likes'),
            'update_dt'  => date('Y-m-d H:i:s', TIMESTAMP),
            'updat_uid'  => App::getUser()->getUid(),
        );

        return Db::update(Db::table('shop'), $data, array('shop_id' => $shop_id));
    }

    public function delete($shop_id){
        $shop_id = intval($shop_id);
        Db::query('delete from '.Db::table('shop'). 'where shop_id = `$shop_id`');
        return Db::affectedRows();
    }

    public function delete_batch(array $shop_ids){
        $stmt = Db::prepare('delete from '.Db::table('shop'). 'where shop_id = ?');
        $stmt->bind_params('i', $shopid);
        foreach($shop_ids as $shopid){
            $stmt->execute();
        }
        return Db::affectedRows();
    }

}

?>